package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.StudentLeaveApply;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xmy.cultivate.respons.LeaveApply;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 学生请假申请表 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-11-10
 */
public interface StudentLeaveApplyMapper extends BaseMapper<StudentLeaveApply> {

    //查询申请待处理的数据
//    @Select("SELECT s_l_a.*  FROM student_leave_apply s_l_a LEFT JOIN grade g ON g.id=s_l_a.grade_id WHERE s_l_a.STATUS = 0 AND g.deleted = 0 AND g.teacher_id = #{adminId}g.teacher_id = #{adminId} ORDER BY created_at ")
//    List<StudentLeaveApply> getNotHandleLeaveList(@Param("adminId") Long adminId);
    @Select("SELECT" +
            " s_l_a.id," +
            " s_l_a.school_date," +
            " s_l_a.leave_reason," +
            " s_l_a.refuse_reason," +
            " s_l_a.created_at," +
            " s_l_a.status," +
            " g.name," +
            " s.name AS subjects," +
            " s1.name studentName" +
            " FROM" +
            " student_leave_apply s_l_a" +
            " LEFT JOIN grade g ON g.id = s_l_a.grade_id           " +
            " JOIN subjects s on g.subjects_id = s.id" +
            " JOIN student s1 on s1.id = s_l_a.student_id" +
            " WHERE" +
            " s_l_a.STATUS = 0 " +
            " AND g.deleted = 0  AND s.deleted = 0  AND s1.deleted = 0 AND g.teacher_id = #{adminId} ORDER BY s_l_a.created_at ")
    List<LeaveApply> getNotHandleLeaveList(@Param("adminId") Long adminId);

    //查询申请已处理的数据
//    @Select("SELECT s_l_a.*  FROM student_leave_apply s_l_a LEFT JOIN grade g ON g.id=s_l_a.grade_id WHERE s_l_a.STATUS <> 0 AND g.deleted = 0 AND g.teacher_id = #{adminId} ORDER BY created_at DESC")
//    List<StudentLeaveApply> getHandleLeaveList(@Param("adminId") Long adminId);
    @Select("SELECT" +
            " s_l_a.id," +
            " s_l_a.school_date," +
            " s_l_a.leave_reason," +
            " s_l_a.refuse_reason," +
            " s_l_a.created_at," +
            " s_l_a.status," +
            " g.name," +
            " s.name AS subjects," +
            " s1.name studentName" +
            " FROM" +
            " student_leave_apply s_l_a" +
            " LEFT JOIN grade g ON g.id = s_l_a.grade_id      " +
            " JOIN subjects s on g.subjects_id = s.id" +
            " JOIN student s1 on s1.id = s_l_a.student_id" +
            " WHERE" +
            " s_l_a.STATUS <> 0 " +
            " AND g.deleted = 0  AND s.deleted = 0  AND s1.deleted = 0 AND g.teacher_id = #{adminId} ORDER BY s_l_a.created_at DESC")
    List<LeaveApply> getHandleLeaveList(@Param("adminId") Long adminId);

    @Select("SELECT s_l_a.*  FROM student_leave_apply s_l_a LEFT JOIN grade g ON g.id=s_l_a.grade_id WHERE s_l_a.STATUS = #{status} AND g.teacher_id = #{adminId} ORDER BY created_at ")
    List<StudentLeaveApply> getLeaveApplyList(@Param("adminId") Long adminId, @Param("status") Integer status);

}
